home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / pccts.zip / GENMK.C < prev    next >
C/C++ Source or Header  |  1992-12-08  |  2KB  |  116 lines

  1. /*
  2.  * genmk -- a program to make makefiles for PCCTS
  3.  *
  4.  * genmk project f1.g f2.g f3.g ...
  5.  *
  6.  * where fi.g are the grammar files you want a makefile for
  7.  *
  8.  * ANTLR 1.06
  9.  * Terence John Parr 1989, 1990, 1991, 1992
  10.  * Purdue University
  11.  */
  12. #include <stdio.h>
  13.  
  14. char *dlg = "parser.dlg";
  15. char *err = "err.c";
  16. char *hdr = "stdpccts.h";
  17. char *tok = "tokens.h";
  18.  
  19. main(argc, argv)
  20. int argc;
  21. char **argv;
  22. {
  23.     char *project;
  24.     char **files;
  25.  
  26.     if ( argc < 3 )
  27.     {
  28.         fprintf(stderr, "genmk: genmk project f1.g f2.g f3.g ...\n");
  29.         exit(-1);
  30.     }
  31.     project = argv[1];
  32.     files = &argv[2];
  33.     mk(project, files, argc-2);
  34.     return 0;
  35. }
  36.  
  37. mk(project, files, n)
  38. char *project;
  39. char **files;
  40. int n;
  41. {
  42.     printf("#\n");
  43.     printf("# PCCTS makefile for: ");
  44.     pfiles(files, n, NULL);
  45.     printf("\n");
  46.     printf("#\n");
  47.     printf("DLG_FILE = %s\n", dlg);
  48.     printf("ERR_FILE = %s\n", err);
  49.     printf("HDR_FILE = %s\n", hdr);
  50.     printf("TOK_FILE = %s\n", tok);
  51.     printf("K = 1\n");
  52.     printf("ANTLR_H = .\n");
  53.     printf("BIN = .\n");
  54.     printf("ANTLR = $(BIN)/antlr\n");
  55.     printf("DLG = $(BIN)/dlg\n");
  56.     printf("CFLAGS = -I. -I$(ANTLR_H)\n");
  57.     printf("AFLAGS = -fe %s -fh %s -fl %s -ft %s -k $(K) -gk\n",
  58.            err, hdr, dlg, tok);
  59.     printf("DFLAGS = -C2 -i\n");
  60.     printf("GRM = ");
  61.     pfiles(files, n, NULL);
  62.     printf("\n");
  63.     printf("SRC = scan.c ");
  64.     pfiles(files, n, "c");
  65.     printf(" err.c\n");
  66.     printf("OBJ = scan.o ");
  67.     pfiles(files, n, "o");
  68.     printf(" err.o\n");
  69.     printf("\n%s: $(OBJ) $(SRC)\n", project);
  70.     printf("    cc -o %s $(CFLAGS) $(OBJ)\n", project);
  71.     printf("\n");
  72.     pfiles(files, n, "c");
  73.     printf(" %s : ", dlg);
  74.     pfiles(files, n, NULL);
  75.     printf("\n");
  76.     printf("    $(ANTLR) $(AFLAGS) ");
  77.     pfiles(files, n, NULL);
  78.     printf("\n");
  79.     printf("\n");
  80.     printf("scan.c : %s\n", dlg);
  81.     printf("    $(DLG) $(DFLAGS) %s scan.c\n", dlg);
  82.     printf("\n");
  83. }
  84.  
  85. pfiles(files, n, suffix)
  86. char **files;
  87. int n;
  88. char *suffix;
  89. {
  90.     int first=1;
  91.  
  92.     while ( n>0 )
  93.     {
  94.         char *p = &(*files)[strlen(*files)-1];
  95.         if ( !first ) putchar(' ');
  96.         first=0;
  97.         while ( p > *files && *p != '.' ) --p;
  98.         if ( p == *files )
  99.         {
  100.             fprintf(stderr,
  101.                     "genmk: filenames must be file.suffix format: %s\n",
  102.                     *files);
  103.             exit(-1);
  104.         }
  105.         if ( suffix == NULL ) printf("%s", *files);
  106.         else
  107.         {
  108.             *p = '\0';
  109.             printf("%s.%s", *files, suffix);
  110.             *p = '.';
  111.         }
  112.         files++;
  113.         --n;
  114.     }
  115. }
  116.